//会员管理
var member_index_ops={
	init:function(){
		this.eventBind();
	},
	eventBind:function(){
		//保存事件
		$(".save").click(function(){
			var btn_target=$(this);
			if(btn_target.hasClass("disabled")){
				common_ops.alert("正在处理!");
				return;
			}
			var nickname_target=$("input[name=nickname]");
			var nickname=$("input[name=nickname]").val();

			var mobile_target=$("input[name=mobile]"); 
			var mobile=$("input[name=mobile]").val();
			var id=$("input[name=id]").val();
			if($.trim(nickname).length<1){
				common_ops.tip("名称不能为空",nickname_target);
				return;
			}
			if($.trim(mobile).length<1){
				common_ops.tip("手机不能为空",mobile_target);
				return;
			}
			
			btn_target.addClass("disabled");

			$.ajax({
				url:common_ops.buildWebUrl('/member/set'),
				type:"POST",
				data:{
					nickname:nickname,
					mobile:mobile,
					id:id,
				},
				dataType:"json",
				success:function(res){
					btn_target.removeClass("disabled");
					var callback=null;
					console.log(res);
					if(res.code==200){
						callback=function(){
							window.location.href=window.location.href;
						};
					}
					common_ops.alert(res.msg,callback);
				},
			});
		});
		//点击搜索事件
		
		//会员删除,恢复按钮点击事件
		var that=this;
		$(".remove").click(function(){
			that.ops("remove",$(this).attr('data'));
		});
		$(".recover").click(function(){
			that.ops("recover",$(this).attr('data'));
		});

	},
	ops:function(act,id){
		callback={
			"ok":function(){
				$.ajax({
					url:common_ops.buildWebUrl("/member/ops"),
					type:"POST",
					data:{
						id:id
					},
					dataType:"json",
					success:function(res){
						callback=null;
						if(res.code==200){
							callback=function(){
								window.location.href=window.location.href;
							}
						}
						common_ops.alert(res.msg,callback);
					}
				});
			},
			"cancel":function(){

			},
		};
		common_ops.confirm( (act=="remove"?"你确定删除吗?":"你确定恢复吗"),callback );
	},
	
};
$(document).ready(function(){
	member_index_ops.init();
});